package com.hua.giftool.utils

import android.app.DownloadManager
import android.content.Context
import android.net.Uri
import android.os.Environment

class DownloadController(private val context: Context) {

    fun enqueueDownload(url: String, fileName: String) {
        val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager

        val request = DownloadManager.Request(Uri.parse(url))
            .setTitle("Downloading App Update")
            .setDescription(fileName)
            .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
            .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
            .setMimeType("application/vnd.android.package-archive")

        downloadManager.enqueue(request)
    }
}
